package com.pengshun.modules.api.pay.controller;

import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.coal.validator.Second;
import com.pengshun.modules.api.order.service.dto.MerchantOrderDto;
import com.pengshun.modules.api.pay.service.UnifiedorderResult;
import com.pengshun.modules.api.pay.service.WechatPayService;
import com.pengshun.modules.common.BillType;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import com.pengshun.modules.common.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequiredArgsConstructor
@Api(tags = "微信支付相关")
@RequestMapping("/api/wechat/pay")
@ApiIgnore
public class WechatPayController {


    private final WechatPayService wechatPayService;

    @ApiOperation(value = "结果查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "outTradeNo", value = "商户订单号", dataType = "int", required = true, paramType = "query"),
    })
    @PostMapping(value = "/order-query", produces = "application/json; charset=utf-8")
    public BaseResult orderQuery(String outTradeNo)  throws Exception {
        BaseResult result=wechatPayService.orderQuery(outTradeNo);
        return result;
    }

    @ApiOperation(value = "支付回调接口", notes = "")
    @RequestMapping(value = "/notify", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String payNotify(HttpServletRequest request) throws Exception {
        String res = wechatPayService.notifys(request);
        return res;

    }

}
